package sundial;

import java.awt.*;
import javax.swing.*;

public class Genome extends JPanel{

	private int maxHeight = 500;
	private int minHeight = 100;
	
	private double latitude;
	
    // Create a constructor method
    public Genome(SundialCompute calculations){
        super();
        
        //init latitude
        latitude = calculations.getLatitude();
    }

    public void paintComponent(Graphics g){
    	
    	long convertDouble;
    	double opposite;
    	
    	opposite = getOpposite(latitude);
    	
    	convertDouble = Math.round(opposite);
    	
    	if (convertDouble < 500)
    	{
    		//adjacent
        	g.drawLine(100,minHeight,100,maxHeight);
        	
    		//drawing opposite
    		g.drawLine(100,minHeight,(int)convertDouble,minHeight);
    	
    		//drawing hypotenuse
    		g.drawLine((int)convertDouble,minHeight,100,maxHeight);
    	}
    	else
    	{
    		//will result in couple of pixels off, but will fix too large problem
    		while (convertDouble > 500)
    		{
    			if (convertDouble % 2 == 1)
    			{
    				convertDouble /= 3;
    				maxHeight /= 3;
    			}
    			else
    			{
    				convertDouble /= 2;
    				maxHeight /= 2;
    			}
    		}
    		
    		//adjacent
        	g.drawLine(100,minHeight,100,maxHeight);
        	
    		//drawing opposite
    		g.drawLine(100,minHeight,(int)convertDouble,minHeight);
    	
    		//drawing hypotenuse
    		g.drawLine((int)convertDouble,minHeight,100,maxHeight);
    	}
    }
    
    //no parameter, parameter temporary
    public static JFrame makeGenome(SundialCompute calculations)
    {
    	JFrame newFrame = new JFrame("Genome");
    	newFrame.setSize(600,600);
    	
    	Genome gnomon = new Genome(calculations);
    	newFrame.setContentPane(gnomon);
    	/////newFrame.setVisible(true);
    	
    	return newFrame;
    }
    
    //no parameter, parameter temporary
    public double getOpposite(double latitude)
    {
    	//double latitude = 10;
    	
    	//convert to radians from degrees/ get latitude
    	latitude = Math.toRadians(latitude);
    	
    	double opposite;
    	
    	opposite = Math.tan(latitude) * 400;
    	
    	//accounting for 100 extra from left
    	opposite += 100;
    	
    	return opposite;
    	
    }
}